Ext.define('Zm.view.line.Property',{
    alias:'widget.lineproperty',
    extend:'Ext.grid.Panel',
    requires:[
        'Ext.grid.RowNumberer',
        'Ext.ux.TreePicker'
    ],
    initComponent:function(){
        var me = this,
            lang = Zm.i18n.Lang;
            
        me.cellEditing = Ext.create('Ext.grid.plugin.CellEditing',{errorSummary:false});
        me.devid = 0;
        me.portTree = Ext.create('Zm.store.PortTree');
        Ext.apply(me,{
            title: lang.tLineInfo,
            layout:'fit',
            store:'PortInfo',
            plugins: [me.cellEditing],
            columns:[
                {xtype:'rownumberer',text:lang.tIndex,width:35},
                {text:lang.tDdname,dataIndex:'devid',renderer:me.rendDev,flex:1,editor:{
                    xtype:'treepicker',
                    store: me.portTree,
                    rootVisible:false,
                    displayField:'text'
                }}
            ],
            viewConfig : {
                loadMask : false
            },
            dockedItems: [{
                xtype:'toolbar',
                dock:'top',
                items:[{
                    text:lang.tAddLine,
                    iconCls:'lineadd',
                    disabled: true,
                    action:'add'
                },{
                    text:lang.tDel,
                    iconCls:'linedel',
                    disabled: true,
                    action:'del'
                }]
            }],
            listeners:{
                edit:me.onEdit,
                selectionchange:me.onSelChange
            }
        });
        
        me.addEvents('propertychange');
        me.callParent(arguments);
        me.store.on('metachange',me.onMetaChange,me);
    },
    rendDev:function(val,meta,record,rowIndex,colIndex,store,view){
        return record.get('devname');
    },
    onSelChange: function(selModel, selections){
        var me = this,
            flag = selections.length === 0,
            btn2 = me.down('button[action=del]');
        btn2.setDisabled(flag);
    },
    setValue:function(devid){
        var me = this,
            proxy = me.store.getProxy(),
            proxy1 = me.portTree.getProxy();
        me.devid = devid;
        proxy.extraParams = {devid:devid};
        me.store.load();
        proxy1.extraParams = {devid:devid};
        me.portTree.load();
    },
    onEdit:function(editor,e,eOpt){
        var me = this;
        me.fireEvent('propertychange',me,editor,e,eOpt);
    },
    onMetaChange:function(store,meta,eOpts){
        var me = this,title='',
            lang = Zm.i18n.Lang,
            btn = me.down('button[action=add]');
        if(meta.editable) 
            btn.setDisabled(false);
        else
            btn.setDisabled(true);
        if(meta.devname){
            title = Ext.String.format(lang.tLineInfoTip,meta.devname);
        }
        me.setTitle(title);
    }
});